#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "barreoutils.h"
#include "callback.h"
#include "document.h"
#include "menu.h"

docs_t docs = {NULL, NULL, NULL};

int main (int argc, char **argv)
{
  GtkWidget *p_window = NULL;
  GtkWidget *p_main_box = NULL;
  GtkWidget *p_text_view = NULL;

  /* Initialisation de GTK+ */
  gtk_init (&argc, &argv);

  /* Creation de la fenetre principale de notre application */
  p_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  //gtk_window_maximize (GTK_WINDOW (p_window));
  gtk_widget_set_size_request(p_window, 700, 600);
  gtk_window_set_resizable (GTK_WINDOW(p_window), FALSE);
  gtk_window_set_position(GTK_WINDOW(p_window), GTK_WIN_POS_CENTER);
  gtk_window_set_title (GTK_WINDOW (p_window), " Interprete mini-basic - Projet C _DIC1 / ESP 2013-2014");
  g_signal_connect (G_OBJECT (p_window), "destroy", G_CALLBACK (cb_quit), NULL);
  docs.p_main_window = GTK_WINDOW (p_window);

  /* Creation du conteneur principal */
  p_main_box = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (p_window), p_main_box);

  p_text_view = gtk_text_view_new ();

  /* Creation du menu */
  gtk_box_pack_start (GTK_BOX (p_main_box), GTK_WIDGET (menu_new (p_text_view)), FALSE, FALSE, 0);

  /* Creation de la barre d'outils */
  gtk_box_pack_start (GTK_BOX (p_main_box), GTK_WIDGET (toolbar_new (p_text_view)), FALSE, FALSE, 0);

  /* Creation de la zone de texte */
  {
    GtkTextBuffer *p_text_buffer = NULL;
    GtkWidget *p_scrolled_window = NULL;

    p_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (p_scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_box_pack_start (GTK_BOX (p_main_box), p_scrolled_window, TRUE, TRUE, 0);
    p_text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (p_text_view));
    g_signal_connect (G_OBJECT (p_text_buffer), "changed", G_CALLBACK (cb_modifie), NULL);
    gtk_widget_set_sensitive (p_text_view, FALSE);

    gtk_container_add (GTK_CONTAINER (p_scrolled_window), p_text_view);
  }

    GtkStatusbar *p_statusbar= NULL;
    p_statusbar= gtk_statusbar_new ();
    gtk_box_pack_start (GTK_BOX (p_main_box), GTK_WIDGET (p_statusbar), FALSE, FALSE, 0);

  /* Affichage de la fenetre principale */
  gtk_widget_show_all (p_window);
  /* Lancement de la boucle principale */
  gtk_main ();
  return EXIT_SUCCESS;
}
